home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gekikoh Dennoh Club 1
/
Gekikoh Dennoh Club Vol. 1 (Japan).7z
/
Gekikoh Dennoh Club Vol. 1 (Japan) (Track 1).bin
/
kowin
/
archive
/
apl
/
gview120.lzh
/
gviewsrc.lzh
/
pic_load.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-02-13
|
3KB
|
132 lines
/* Copyright 1992 H.Ogasawara (COR.) */
#include <corlib.h>
#include <sys_doslib.h>
#include "gview.h"
#define WSIZE (1024*32)
static int sizex, sizey;
static unsigned char com[256];
void *PicBUFADR;
static void
ToSmall( gp )
GVIEW *gp;
{
unsigned short *str= gp->buf, *ptr= gp->buf;
int y= 255;
for(; y >= 0 ; y-= 3 ){
int x;
for( x= 256 ; x-- >= 0 ;){
unsigned int a= *ptr++,
b= *ptr++,
c= ptr[512-2],
d= ptr[512-1];
*str++=
((((a&0xf800)+(b&0xf800)+(c&0xf800)+(d&0xf800))>>2)&0xf800)+
((((a&0x07c0)+(b&0x07c0)+(c&0x07c0)+(d&0x07c0))>>2)&0x07c0)+
((((a&0x003e)+(b&0x003e)+(c&0x003e)+(d&0x003e))>>2)&0x003e);
}
ptr+= 512;
for( x= 256 ; x-- >= 0 ;){
unsigned int a= *ptr++,
b= *ptr++,
c= ptr[512-2],
d= ptr[512-1],
e= ptr[1024-2],
f= ptr[1024-1],
g= ptr[1536-2],
h= ptr[1536-1];
*str++=
((((a&0xf800)+(b&0xf800)+(c&0xf800)+(d&0xf800)+
(e&0xf800)+(f&0xf800)+(g&0xf800)+(h&0xf800))>>3)&0xf800)+
((((a&0x07c0)+(b&0x07c0)+(c&0x07c0)+(d&0x07c0)+
(e&0x07c0)+(f&0x07c0)+(g&0x07c0)+(h&0x07c0))>>3)&0x07c0)+
((((a&0x003e)+(b&0x003e)+(c&0x003e)+(d&0x003e)+
(e&0x003e)+(f&0x003e)+(g&0x003e)+(h&0x003e))>>3)&0x003e);
}
ptr+= 1536;
}
SETBLOCK( gp, ((char*)gp->buf) - (char*)gp + 256*170*2 );
gp->h= 256;
gp->v= 170;
}
static void
PicResize( gp )
GVIEW *gp;
{
if( sizex != 512 ){
unsigned short *str= gp->buf, *ptr= gp->buf;
int y;
for( y= 0 ; y< sizey ; y++, ptr+= (512-sizex) ){
int x;
for( x= 0 ; x< sizex ; x++ )
*str++= *ptr++;
}
}
SETBLOCK( gp, ((char*)gp->buf) - (char*)gp + sizey*sizex*2 );
gp->h= sizex;
gp->v= sizey;
}
static
size_check( fn )
{
unsigned char *p;
READ( fn, p= com, 256 );
if( *p != 'P' || p[1] != 'I' || p[2] != 'C' ){
CLOSE( fn );
GV_Err( "PICフォーマットが違います" );
return FALSE;
}
for( com[255]= 0x1a ; *p != 0x1a ; p++ );
*p++= '\0';
for( com[255]= 0 ; *p != 0x00 ; p++ );
p++; /* skip NUL */
SEEK( fn, p-com, 0 );
p+= 2; /* 0 */
p+= 2; /* 15 */
sizex= (*p<<8)+p[1]; p+= 2;
sizey= (*p<<8)+p[1]; p+= 2;
if( sizex > 512 || sizey > 512 ){
GV_Err( "巨大なデータは展開できません" );
return FALSE;
}
return TRUE;
}
GVIEW *
GV_Load_Pic( fname )
char *fname;
{
int fn;
if( (fn= OPEN( fname, 0 ))>= 0 && size_check( fn ) ){
char wbuf[WSIZE];
GVIEW *gp;
if( !(gp= GV_Alloc( 512, 512, WindowAttrGraphic65536,
fname, com+3, 0 )) ){
CLOSE( fn );
GV_Err( "メモリが足りません" );
return NULL;
}
PicBUFADR= gp->buf;
if( PicLoad( fn, 0, 0, wbuf, WSIZE ) < 0 ){
CLOSE( fn );
MFREE( gp );
GV_Err( "PIC展開エラー" );
return NULL;
}
CLOSE( fn );
if( sizex != 512 || sizey != 512 )
PicResize( gp );
else
ToSmall( gp );
return gp;
}
GV_Err( "PICオープンできません" );
return NULL;
}